<template>
	<view class="container">		
		<!-- 状态提示，仅在已完成时显示 -->
		<view v-if="isCompleted" class="status-done">
			<view class="status-icon">
				<image src="/static/check-mark.png" class="check-mark" />
			</view>
			<text class="status-text">已完成</text>
		</view>
		
		<!-- 进度条 -->
		<view class="progress-bar">
			<view class="progress-item">
				<view class="progress-icon completed">
					<image src="/static/check-mark2.png" class="check-mark2" />
				</view>
				<text class="progress-text">待派工</text>
			</view>
			<view class="progress-line completed"></view>
			<view class="progress-item">
				<view class="progress-icon completed">
					<image src="/static/check-mark2.png" class="check-mark2" />
				</view>
				<text class="progress-text">待接单</text>
			</view>
			<view class="progress-line completed"></view>
			<view class="progress-item">
				<view class="progress-icon completed">
					<image src="/static/check-mark2.png" class="check-mark2" />
				</view>
				<text class="progress-text">处理中</text>
			</view>
			<view class="progress-line completed"></view>
			<view class="progress-item">
				<view class="progress-icon completed">
					<image src="/static/check-mark2.png" class="check-mark2" />
				</view>
				<text class="progress-text">已完成</text>
			</view>
		</view>
		
		<!-- 选项卡 -->
		<view class="tabs">
			<view class="tab-item" :class="{ active: activeTab === 0 }" @click="activeTab = 0">
				<text>报修详情</text>
				<view class="tab-line" v-if="activeTab === 0"></view>
			</view>
			<view class="tab-item" :class="{ active: activeTab === 1 }" @click="activeTab = 1">
				<text>处理进度</text>
				<view class="tab-line" v-if="activeTab === 1"></view>
			</view>
			<view class="tab-item" :class="{ active: activeTab === 2 }" @click="activeTab = 2">
				<text>用户评价</text>
				<view class="tab-line" v-if="activeTab === 2"></view>
			</view>
		</view>
		<!-- 内容区域 -->
		<scroll-view class="content" scroll-y>
			<!-- 报修详情 -->
			<view v-if="activeTab === 0 && detail" class="repair-detail">
				<view class="detail-item">
					<text class="detail-label">报修类型：</text>
					<text class="detail-value">{{ detail.repair_type }}</text>
				</view>
				<view class="detail-item">
					<text class="detail-label">故障描述：</text>
					<text class="detail-value">{{ detail.repair_content }}</text>
				</view>
				<view class="detail-item">
					<text class="detail-label">报修时间：</text>
					<text class="detail-value">{{ detail.sub_date }}</text>
				</view>
				<view class="detail-item">
					<text class="detail-label">联系方式：</text>
					<text class="detail-value">{{ detail.sub_name }} {{ detail.sub_tel }}</text>
				</view>
				<view class="detail-item">
					<text class="detail-label">报修地点：</text>
					<text class="detail-value">{{ detail.repair_address }}</text>
				</view>
				<view class="detail-item">
					<text class="detail-label">处理人员：</text>
					<text class="detail-value">{{ detail.handler_name }}</text>
				</view>
				<view class="detail-item">
					<text class="detail-label">完成时间：</text>
					<text class="detail-value">{{ detail.end_date }}</text>
				</view>
			</view>
			<!-- 处理流程 -->
			<view v-if="activeTab === 1" class="timeline">
				<!-- 已完成 -->
				<view class="timeline-item" v-if="detail.end_date">
					<text class="time">{{ detail.end_date }}</text>
					<text class="status">[维修部] {{detail.handler_name}} 已完成</text>
				</view>
				
				<!-- 开始处理 -->
				<view class="timeline-item" v-if="detail.hand_date">
					<text class="time">{{detail.hand_date}}</text>
					<text class="status">[维修部] {{detail.handler_name}} 开始处理</text>
				</view>
				
				<!-- 派工状态 -->
				<view class="timeline-item" v-if="detail.hand_date && detail.handler_name">
					<text class="time">{{detail.hand_date}}</text>
					<text class="status">已派工给 [维修部] {{detail.handler_name}}，正在等待处理</text>
				</view>
				
				<!-- 用户提交 -->
				<view class="timeline-item" v-if="detail.sub_date">
					<text class="time">{{detail.sub_date}}</text>
					<text class="status">用户提交</text>
				</view>
			</view>
			
			<!-- 用户评价，只在已评价时显示 -->
			<view v-if="activeTab === 2 && isCommented" class="evaluation">
				<view class="eval-header">
					<view class="stars">
						<img v-for="n in detail.comment.qualityRating" :key="n" src="/static/star.png" style="width: 40rpx; height: 40rpx;margin-right: 10rpx;" />
					</view>
					<text class="eval-score">{{ detail.comment.qualityRating }}分</text>
				</view>
				<text class="eval-content">{{ detail.comment.feedbackContent }}</text>
				<text class="eval-time">评价时间：{{ detail.comment.end_date }}</text>
			</view>
		</scroll-view>
	</view>
</template>

<script lang="ts" setup>
	import { ref, onMounted } from 'vue'
	import { onLoad, onShow } from '@dcloudio/uni-app' // HBuilderX/uni-app专用

	const activeTab = ref(0)
	const isCompleted = ref(true) // 这里根据实际业务逻辑赋值
	const detail = ref<any>({})
	const isCommented = ref(false) // 是否已评价
	const commentInput = ref({
		qualityRating: 0,
		feedbackContent: ''
	})

	onLoad(() => {
		// 只需加载工单详情
		detail.value = uni.getStorageSync("junmp_order") || {}
		uni.removeStorageSync('junmp_order')
		if(detail.value.comment){
			isCommented.value = true;
		}
	})


</script>
  
<style>
	.container {
		display: flex;
		flex-direction: column;
		background: #F5F5F5;
		height: 100vh;
	}
	/*状态提示*/
	.status-done {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 48rpx;
		background: linear-gradient(to right, #28ADB4, #1E989F);
	}

	.status-icon {
		width: 68rpx;
		height: 68rpx;
		background: #fff;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
		margin-bottom: 16rpx;
	}

	.status-text {
		font-size: 35rpx;
		color: #fff;
	}

	.check-mark {
		width: 47rpx;
		height: 47rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		display: block;
	}

	/*进度条*/
	.progress-bar {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 40rpx 60rpx;
		background-color: #fff;
	}

	.progress-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		z-index: 1;
	}

	.progress-icon {
		width: 45rpx;
		height: 45rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #ddd;
		margin: 0 15rpx;
	}

	.progress-icon.completed {
		background-color: #28ADB4;
	}

	.progress-text {
		font-size: 15px;
		color: #737373;
		margin-top: 12rpx;
		white-space: nowrap;
	}

	.progress-line {
		flex: 1;
		height: 2rpx;
		position: relative;
		top: -20rpx;
	}

	.progress-line.completed {
		background-color: #AEADAE;
	}
	
	.check-mark2{
		width: 30rpx;
		height: 30rpx;
		align-items: center;
		justify-content: center;
		display: block;
	}
	
	.tabs {
		display: flex;
		height: 88rpx;
		background-color: #fff;
		margin-top: 20rpx;
	}

	.tab-item {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: relative;
	}

	.tab-item text {
		font-size: 30rpx;
		color: #AFAFAF;
		font-weight: bold;
	}

	.tab-item.active text {
		color: #28ADB4;
	}

	.tab-line {
		position: absolute;
		bottom: 0;
		width: 120rpx;
		height: 4rpx;
		background-color: #28ADB4;
	}

	.content {
		flex: 1;
		overflow: auto;
		padding: 32rpx;
		background-color: #fff;
		margin-top: 8rpx;
	}

	.repair-detail {
		padding: 0 20rpx;
	}

	.repair-images {
		margin-top: 32rpx;
	}

	.fault-image {
		width: 100%;
		height: 400rpx;
		border-radius: 8rpx;
	}

	.detail-item {
		margin-bottom: 32rpx;
	}

	.detail-label {
		font-size: 16px;
		color: #707070;
		margin-right: 16rpx;
	}

	.detail-value {
		font-size: 16px;
		color: #000;
	}

	.timeline {
		padding: 0 20rpx;
	}

	.timeline-item {
		position: relative;
		padding-left: 40rpx;
		margin-bottom: 40rpx;
	}

	.timeline-item::before {
		content: '';
		position: absolute;
		left: 0;
		top: 12rpx;
		width: 16rpx;
		height: 16rpx;
		background-color: #45C6B9;
		border-radius: 50%;
	}

	.time {
		font-size: 12px;
		color: #AAAAAA;
		display: block;
		margin-bottom: 8rpx;
	}

	.status {
		font-size: 16px;
		color: #333;
		display: block;
	}
	
	/*用户评价*/
	.evaluation {
		padding: 0 60rpx 0 20rpx;
	}

	.eval-header {
		display: flex;
		align-items: center;
		margin-bottom: 32rpx;
	}

	.eval-score {
		font-size: 18px;
		color: #000;
		margin-left: 10rpx;
	}

	.eval-content {
		font-size: 16px;
		color: #333;
		line-height: 1.6;
		margin-bottom: 16rpx;
		display: block;
	}

	.eval-time {
		font-size: 12px;
		color: #ACACAC;
		display: block;
	}
</style>